<template>
  <el-scrollbar class="maxSize">
    <el-form>
      <el-form-item label="题目内容" >
        <el-text>{{props.question.content}}</el-text>
      </el-form-item>
      <el-form-item label="题目类型" prop="type">
        <el-text>{{questionTypes[props.question.type]}}题</el-text>
      </el-form-item>

      <el-form-item label="题目答案" prop="answer">
        <ChoiceAnswerShow :question="props.question"></ChoiceAnswerShow>
      </el-form-item>

      <el-form-item label="题目标签">
        <el-tag v-for="item in allTag">{{item.name}}</el-tag>
      </el-form-item>

    </el-form>
  </el-scrollbar>
</template>

<script setup lang="ts">
import {onMounted, reactive, ref} from "vue";
import {Question, QuestionAnswer, questionTypes, Tag, User} from "../../types/mytypes";
import {FormInstance, FormRules} from "element-plus";
import ChoiceAnswer from "./ChoiceAnswer.vue";
import {QuestionRequest, TagRequest} from "../../request/MyRequset";
import {UserStore} from "../../store/store";
import ChoiceAnswerShow from "./ChoiceAnswerShow.vue";
const props = defineProps<{
  question:Question
}>()
const formRef = ref<FormInstance>()
const emit = defineEmits(["error", "success"]);
const user:User = UserStore.getUser()
//全部标签
let allTag = ref<Tag[]>([])

//====================FN====================

onMounted(async () => {
  allTag.value = (await TagRequest.getByQuestion(props.question.id as number)).data
})

const formRules = reactive<FormRules>({
  content: [
    {type: "string", required: true, message: "不能为空"}
  ],
  type: [
    {type: "number", required: true, message: "不能为空"}
  ],
})

const error = (error: string) => {
  emit("error", error);
}
const success = (msg?: string) => {
  emit("success", msg);
}
</script>

<style scoped lang="scss">
.maxSize {
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
  padding: 10px;
  width: 40em;
  margin-top: 10px;
}
</style>